//
//  AroundViewController.m
//  wuyeviewcon
//
//  Created by dsdf on 16/1/11.
//  Copyright © 2016年 joey. All rights reserved.
//

#import "AroundViewController.h"
#import "xiaoquhoseViewController.h"
#import "xiaoqutuangouViewController.h"
#import "gonggongziyuanzhaoshangViewController.h"


@interface AroundViewController ()<UIScrollViewDelegate>
{
    UIScrollView * _scrollView;
    UIPageControl * _pageControl;
    
    UIScrollView * lableScrollView;
    
    
    
}


@end

@implementation AroundViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
        self.navigationController.navigationBar.barTintColor = [[UIColor alloc] initWithRed:230/255.0 green:55/255.0 blue:55/255.0 alpha:1.0];
    
    self.navigationItem.title=@"小区商务";
    self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
    
    
    
    UIImage * img0 = [UIImage imageNamed:@"矩形-18@2x.png"];
    UIImage * img1 = [UIImage imageNamed:@"矩形-18@2x.png"];
    UIImage * img2 = [UIImage imageNamed:@"矩形-18@2x.png"];
    UIImage * img3 = [UIImage imageNamed:@"矩形-18@2x.png"];
    UIImage * img4 = [UIImage imageNamed:@"矩形-18@2x.png"];
    [self.view addSubview:[self scrollViewWithNSArray:@[img0,img1,img2,img3,img4]]];
    
    
    _pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 216, self.view.frame.size.width, 40)];
    _pageControl.numberOfPages = 5;
    _pageControl.currentPageIndicatorTintColor = [UIColor redColor];
    _pageControl.pageIndicatorTintColor = [UIColor clearColor];
    [_pageControl addTarget:self action:@selector(changePages) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:_pageControl];
    
    /*NSTimer * timer0= */[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(onTime) userInfo:nil repeats:YES];

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 图片滑动视图
-(UIScrollView *)scrollViewWithNSArray:(NSArray *)imageArray {
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 86, self.view.frame.size.width, 192)];
    _scrollView.pagingEnabled = YES;
    _scrollView.contentSize = CGSizeMake(self.view.frame.size.width*imageArray.count, 192);
    self.automaticallyAdjustsScrollViewInsets = NO;
    for (int i =0; i<imageArray.count;i++) {
        UIButton * imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
        imageButton.frame = CGRectMake(self.view.frame.size.width*i, 0, self.view.frame.size.width, 192);
        [imageButton setImage:[imageArray objectAtIndex:i] forState:UIControlStateNormal];
        imageButton.tag = i;
        [imageButton addTarget:self action:@selector(scrollViewImageButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_scrollView addSubview:imageButton];
        
    }
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    
    //设置代理
    _scrollView.delegate = self;
    
    
    return _scrollView;
}

#pragma mark - 点击pageControl方法
-(void)changePages {
    [_scrollView setContentOffset:CGPointMake(_pageControl.currentPage*self.view.frame.size.width, 0) animated:YES];
}

#pragma mark - 定时器方法
//图片定时器
-(void)onTime {
    static int speed=1;
    _pageControl.currentPage+=speed;
    if (_pageControl.currentPage==2||_pageControl.currentPage==0) {
        speed=-speed;
    }
    [_scrollView setContentOffset:CGPointMake(_pageControl.currentPage*self.view.frame.size.width, 0) animated:YES];
}

#pragma mark - 点击滑动视图上的图片的方法
-(void)scrollViewImageButtonClick:(UIButton *)imageButton {
    //    NSLog(@"image=%ld",(long)imageButton.tag);
}
- (IBAction)xiaoqufangchan:(id)sender {
    //小区房产
    xiaoquhoseViewController *demoVC=[[xiaoquhoseViewController alloc]init];
    [demoVC setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentModalViewController:demoVC animated:YES ];
    
    
    
}

- (IBAction)gonggongziyuan:(id)sender {
    //公共资源招商
    
    gonggongziyuanzhaoshangViewController *demoVC=[[gonggongziyuanzhaoshangViewController alloc]init];
    [demoVC setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentModalViewController:demoVC animated:YES ];
    
}
- (IBAction)xiaoqutuangou:(id)sender {
    //小区团购
    xiaoqutuangouViewController *demoVC=[[xiaoqutuangouViewController alloc]init];
    [demoVC setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentModalViewController:demoVC animated:YES ];
    
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
